package com.acheli.rideable.functionLathes.component;

import com.acheli.rideable.entites.RideableEntity;
import com.acheli.rideable.functionLathes.ComponentFL;
import com.acheli.utils.physics.PhysicsEngine;
import net.minecraft.world.phys.Vec3;

public class GroundCheckFL extends ComponentFL {
    double threshold = 3;
    public GroundCheckFL(String ID, RideableEntity vehicle, Vec3 relativePosition, Vec3 relativeBoxLength) {
        super(ID, vehicle, relativePosition, relativeBoxLength);
    }

    @Override
    public void tick() {
        super.tick();
        RideableEntity rideable = getVehicle();
        if (rideable != null) {
            if (PhysicsEngine.isEntityInsideBlock(getBody())) {
                Vec3 speed = rideable.getDeltaMovement();
                double num = speed.y;
                if (num < 0) {
                    if (num < -threshold) {
                        num = -threshold;
                    }
                    rideable.addDeltaMovement(new Vec3(0, -num * 0.007, 0));
                }
                if (num > 0) {
                    if (num > threshold) {
                        num = threshold;
                    }
                    rideable.addDeltaMovement(new Vec3(0, num * 0.0012, 0));
                }
            }
        }
    }
}
